<?php

require_once 'Mobitv/Admin/Action.php';

class ViewAction extends Mobitv_Admin_Action{
    public function execute(){
        //$this->checkPermission();
        $userId = isset($_GET['id']) ? intval($_GET['id']) : 0;
        $userDao = Vega_Dao::factory('Mobitv_Admin_Admin');
        if(!$userId || !$user=$userDao->getDetail($userId)) {
            $this->forward404();
        }
        $arrGroup = $userDao->getGroupList($userId);
        $this->_view->assign('arrGroup', $arrGroup);
        $actionDao = Vega_Dao::factory('Mobitv_Admin_Action');
        $peradmin = $userDao->getAllPermissionAmin($userId);
        $this->_view->assign('peradmin', $peradmin);
        $permissions = $userDao->getPermissionList($userId);
        $modules = $actionDao->getModuleList();        
        if($modules) {
            foreach($modules AS &$module) {
                $actions = array();
                foreach($permissions AS &$permission) {
                    if($permission['module']==$module['name']) {
                        $action['id'] = $permission['id'];
                        $action['name'] = $permission['name'];
                        $action['description'] = $permission['description'];
                        $action['perm'] = is_null($permission['permission']) ? 2 : $permission['permission'];

                        $actions[] = $action;
                    }
                }
                $module['actions'] = $actions;
            }
        }
        $this->_view->assign('user', $user);
        $this->_view->assign('modules', $modules);
    }
}